package com.kcwl.carrier.infrastructure.repository.persostence;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kcwl.carrier.domain.entity.GroupMappingInfo;
import com.kcwl.carrier.domain.repository.IGroupMappingRepository;
import com.kcwl.carrier.infrastructure.repository.mapper.CarrierMappingMapper;
import com.kcwl.carrier.infrastructure.repository.mapper.GroupMappingMapper;
import com.kcwl.carrier.infrastructure.repository.po.GroupMappingPO;
import com.kcwl.ddd.application.constants.YesNoEnum;
import com.kcwl.ddd.domain.repository.BaseRepositoryImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 刘旭超
 * @date 2022年07月11日 16:33
 * @Description
 */
@Service
public class GroupMappingRepositoryImpl extends BaseRepositoryImpl<GroupMappingMapper, GroupMappingPO> implements IGroupMappingRepository {

    @Resource
    private GroupMappingMapper mappingMapper;


    @Override
    public Class<GroupMappingPO> getPoClass() {
        return GroupMappingPO.class;
    }

    @Override
    public GroupMappingPO getMappingInfo(Long mappingId, Long groupId) {
        QueryWrapper<GroupMappingPO> wrapper = new QueryWrapper<>();
        wrapper.eq("group_id", groupId);
        wrapper.eq("mapping_id", mappingId);
        return mappingMapper.selectOne(wrapper);
    }

    @Override
    public List<GroupMappingPO> queryByGroupIdAndUserId(Long groupId, Long userId) {
        LambdaQueryWrapper<GroupMappingPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupMappingPO::getGroupId,groupId);
        wrapper.eq(GroupMappingPO::getCreateId,userId);
        wrapper.eq(GroupMappingPO::getDeleted, YesNoEnum.NAY.getValue());
        return this.mappingMapper.selectList(wrapper);
    }
}
